package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.deepdesigner.pojo.DtsCollect;
import top.deepdesigner.service.DtsCollectService;

import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:26:43 <br/>
 */
@Service
public class DtsCollectServiceImpl extends ServiceImpl<BaseMapper<DtsCollect>, DtsCollect> implements DtsCollectService {
  @Override
  public Long getCollectCount() {
    return this.count();
  }

  @Override
  public List<DtsCollect> getCollectList(Integer page, Integer limit, String sort, String order, Integer userId, Integer valueId) {
    QueryWrapper<DtsCollect> wrapper = new QueryWrapper<>();
    wrapper
        .eq(userId != null, "user_id", userId)
        .eq(valueId != null, "value_id", valueId)
        .orderBy(true, "asc".equalsIgnoreCase(order), sort);
    Page<DtsCollect> userPage = new Page<>(page, limit);
    return this.page(userPage, wrapper).getRecords();
  }
}